package fun.coding.effective.java;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestJavaLang {

	public void foobar() {
		ArrayList<Integer> a = new ArrayList<Integer>();
		a.add(1);
		a.add(2);
		
		foo(a);
		
	}
	
	/* Like I said, this should totally be fine defining an interface and pass an implementation.
	 * */
	public void foo(List<Integer> l) {
		for(int i : l)
			System.out.print(i + " ");
	}
	
	public static void main(String[] args) {
	    
	    String s = "a";
	    System.out.println("substring of begin index equal to end index is " + s.substring(0, 1));
	    
	    System.out.println("number of ways is " + Nways(6));
	    
	    
	    /*
		TestJavaLang tjl = new TestJavaLang();
		tjl.foobar();
		
		long t1 = System.currentTimeMillis();
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		long t2 = System.currentTimeMillis();
		System.out.println("t1 " + t1 + " t2 " + t2 + "t2 - t1:" + (t2-t1));
		
		testPatternRegexMatching();
		*/
	}
	
	public static void testPatternRegexMatching() {
		Pattern p = Pattern.compile("[xiay]*");
		Matcher m = p.matcher("xiay");
		System.out.println(m.matches());
		
		
	}
	
	
    // Stephy's code. 
    public static int Nways (int m) {
        int coins[] = {1, 5, 10, 25};
        Arrays.sort(coins);
        int num = Nways_helper(0, m, coins);
        return num;
    }
    
    public static int Nways_helper(int n, int m, int[] coins) {
        if (m == 0) {
            return 0;
        }
        if (m < 0) {
            return -1000;
        }
        for (int i = 0; i < coins.length; i++) {
            int coin = coins[i];
            if (coin <= m) {
                int temp = Nways_helper(n, m - coin, coins);

            }
            n = n + 1;
        }
        return n;
    }
}
